home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / EDIT4.ASM < prev    next >
Assembly Source File  |  1986-12-13  |  5KB  |  151 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * Editor Auxiliary Functions
  13.  
  14.     xref    cmd_w,lineed,printf,to_end,write_out
  15.     xdef    prompt,dirty,ask,eof,cnt_nl,seek,chk_blk,default
  16.     xdef    putfile
  17.  
  18. #edit.h
  19.  
  20. *****************************************************************
  21. * EOF - moves cursor to end of file
  22. eof:
  23.     bsr    to_end        * move everything before cursor
  24.     bsr    cnt_nl        * count newlines behind cursor
  25.     rts
  26. *****************************************************************
  27. * CNT_NL - count newlines behind cursor
  28. cnt_nl:
  29.     move.l    b_buf(a5),a0    * a0 is search start address
  30.     move.l    b_gap(a5),d0    * compute number of bytes
  31.     sub.l    a0,d0        * d0 is number of file bytes
  32.     clr.w    d1        * d1 is newline counter
  33.     move.b    #10,d2        * do register compare - faster
  34.     bra    sk0_nl        * loop test before loop body
  35. lp0_nl:
  36.     cmp.b    (a0)+,d2    * look for newline
  37.     bne    sk0_nl        * nope.
  38.     addq.w    #1,d1        * increment line counter
  39. sk0_nl:
  40.     dbra    d0,lp0_nl    * loop test
  41.     move.w    d1,log_lin(a5)    * save new logical line count
  42.     rts
  43. *****************************************************************
  44. * DIRTY - marks file as modified, and clears block markers
  45. dirty:
  46.     clr.l    blk_st(a5)    * reset block start marker
  47.     clr.l    blk_end(a5)    * reset block end marker
  48.     move.w    #-1,modify(a5)    * set file modified flag
  49.     rts
  50. *****************************************************************
  51. * SEEK - moves the cursor to the location in d0
  52. seek:
  53.     move.l    b_gap(a5),a0    * gap start address in A0
  54.     move.l    e_gap(a5),a1    * gap end location in A1
  55.     sub.l    a0,d0        * calculate characters to dest.
  56.     bgt    sk1_sk        * move towards end of file
  57.     neg.w    d0        * take abs() of char count
  58.     bra    sk2_sk        * loop test before branch
  59. lp0_sk:
  60.     move.b    -(a0),-(a1)    * move towards start of file
  61. sk2_sk:
  62.     dbra    d0,lp0_sk    * to start of file loop
  63.     bra    sk0_sk        * get out
  64. lp1_sk:
  65.     move.b    (a1)+,(a0)+    * move towards end of file
  66. sk1_sk:
  67.     dbra    d0,lp1_sk    * to end of file loop
  68. sk0_sk:
  69.     move.l    a0,b_gap(a5)    * reset gap start address
  70.     move.l    a1,e_gap(a5)    * reset gap end address
  71.     rts
  72. *****************************************************************
  73. * CHK_BLK - checks for valid block markers
  74. chk_blk:
  75.     tst.l    blk_st(a5)    * check if start is marked
  76.     beq    sk0_cb        * branch if not
  77.     tst.l    blk_end(a5)    * check if end is marked
  78.     beq    sk1_cb        * branch if not
  79.     move.l    blk_end(a5),d0    * check if end is after start
  80.     cmp.l    blk_st(a5),d0    
  81.     ble    sk3_cb        * branch if mismarked
  82.     clr.w    d0        * get "ok" return code
  83.     bra    sk2_cb        * branch out
  84. sk0_cb:
  85.     move.w    #7,ed_err(a5)    * show start not marked error
  86.     bra    sk2_cb
  87. sk1_cb:
  88.     move.w    #8,ed_err(a5)    * show end not marked error
  89.     bra    sk2_cb
  90. sk3_cb:
  91.     move.w    #9,ed_err(a5)    * show mismark error
  92. sk2_cb:
  93.     rts
  94. *****************************************************************
  95. * DEFAULT: User hits unspecified subcommand key
  96. default:
  97.     rts
  98. *****************************************************************
  99. * PUTFILE - puts the file to disk - returns D0 nonzero on error
  100. putfile:
  101.     bsr    to_end        * move all text behind cursor
  102.     lea    fname(a5),a0    * load name for file write
  103.     move.l    b_buf(a5),a1    * start of data to write
  104.     move.l    b_gap(a5),d1    * calculate number of bytes
  105.     sub.l    a1,d1        * D1 is numbers of bytes to write
  106.     bsr    write_out    * write the file to disk
  107.     tst.w    d0        * check return code
  108.     beq    sk0_pf        * skip error message with no err
  109.     move.w    #3,ed_err(a5)    * load edit error code
  110. sk0_pf:
  111.     rts
  112. *****************************************************************
  113. * PROMPT - outputs a prompt in command window. A0 points to prmt
  114. prompt:
  115.     move.l    a0,-(a7)    * push parameter string address
  116.     move.l    #cmd_w,a0    * get command window address
  117.     move.w    w_ulcy(a0),-(a7)  push Y screen address
  118.     move.w    w_ulcx(a0),-(a7)  push X screen address
  119.     move.l    #p_str,-(a7)    * push format string address
  120.     bsr    printf        * output prompt
  121.     addq.l    #8,a7        * adjust stack
  122.     move.l    (a7)+,a0    * restore a0
  123.     rts
  124. p_str:    dc.b    '%v%-78s',0
  125.     dc.w    0
  126. *****************************************************************
  127. * ASK - prompts human for string input - A0 is prompt string,
  128. *    A1 is input string
  129. ask:
  130.     bsr    prompt        * output prompt string
  131.     move.l    #cmd_w,a2    * a2 has output limits
  132.     move.w    w_ulcx(a2),d0    * d0 will count be X offset
  133. lp0_ask:
  134.     tst.b    (a0)+        * see if we have a null
  135.     beq    sk0_ask        * jump out if null
  136.     addq.w    #1,d0        * increment X position
  137.     bra    lp0_ask        * loop again for strlen
  138. sk0_ask:
  139.     move.w    w_lrcx(a2),d1    * d1 is input window right edge
  140.     sub.w    d0,d1        * d1 is now max chars in input
  141.     move.w    d1,-(a7)    * push max number for lineed
  142.     move.w    d0,-(a7)    * push screen column
  143.     move.w    w_ulcy(a2),-(a7)  push screen line
  144.     move.l    a1,-(a7)    * push input string address
  145.     bsr    lineed        * go edit input line
  146.     add.l    #10,a7        * adjust stack
  147.     rts
  148.  
  149.     end
  150.